package com.chapter03;

import com.bdqn.util.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

public class Test02_Update {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Connection connection = JDBCUtils.getConnection();

//        Statement statement = connection.createStatement();
//        String sql = "UPDATE grade SET GradeName = '知道' WHERE GradeId = 105;";
//        int i = statement.executeUpdate(sql);
        String sql = "UPDATE grade SET GradeName = ? WHERE GradeId = ?;";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setObject(1,"aa");
        preparedStatement.setObject(2,104);

        int i = preparedStatement.executeUpdate();
        if (i > 0) {
            System.out.println("修改成功");
        } else {
            System.out.println("修改失败");
        }

        preparedStatement.close();
        connection.close();
    }
}
